package cn.dao.controller;

import cn.entity.User;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController {
    Logger logger = Logger.getLogger(HelloController.class);

    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public ModelAndView hello(@RequestParam(value = "userName",required = false) String realName) {
        logger.info("你好"+realName+"欢迎来到 Spring MVC 课堂");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("realName",realName);
        modelAndView.setViewName("hello");
        return modelAndView;
    }
    @RequestMapping(value = "/hello2",method = RequestMethod.GET)
    public String hello2(Model model, @RequestParam(value = "userName",required = false) String realName) {
        logger.info("你好"+realName+"欢迎来到 Spring MVC 课堂2");
        model.addAttribute("realName",realName);
        model.addAttribute(realName);
        User user = new User();
        user.setUserName(realName);
        model.addAttribute(user);
        model.addAttribute("userName",user);
        return "hello2";
    }
    @RequestMapping(value = "/show",method = RequestMethod.GET)
    public String show(Model model,@RequestParam(value = "realName",required = false) String realName){
       model.addAttribute("realName",realName);
        return "show";
    }
}
